package binaryTree;


public class Class99_01 {

    public TreeNode getMaxValNode(TreeNode root){
        if (root==null){
            return null;
        }
        TreeNode maxNode=root;
       TreeNode leftNode = getMaxValNode(root.left);
        TreeNode rightNode = getMaxValNode(root.right);
        if (leftNode!=null&&leftNode.val>maxNode.val){
            maxNode=leftNode;
        }
        if (rightNode!=null&&rightNode.val>maxNode.val){
            maxNode=rightNode;
        }
        return maxNode;

    }

    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(2);
        TreeNode treeNode3 = new TreeNode(3);
        treeNode2.left=treeNode1;
        treeNode2.right=treeNode3;

        Class99_01 class99_01 = new Class99_01();
        TreeNode maxValNode = class99_01.getMaxValNode(treeNode2);
        System.out.println(maxValNode.val);

    }


}
